#include <gtk/gtk.h>

void on_font_select_ok(GtkWidget *button, GtkFontSelectionDialog *fs)
{
	GtkWidget *dialog;
	gchar message[1024];
	gchar *s = gtk_font_selection_dialog_get_font_name(fs);
/*

PangoFontDescription * pango_font_description_from_string
                                                        (const char *str);

void gtk_widget_modify_font (GtkWidget *widget, PangoFontDescription *font_desc);
*/
	sprintf(message, "你选择的字体是%s\n", s);
	dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT,
					GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
					message, NULL);
	g_free(s);
	gtk_dialog_run(GTK_DIALOG(dialog));
	gtk_widget_destroy(dialog);
	gtk_widget_destroy(GTK_WIDGET(fs));
}


void on_button_clicked(GtkWidget *button, gpointer userdata)
{
	GtkWidget *dialog;
	dialog = gtk_font_selection_dialog_new("请选择一种字体：");
	gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);

	gtk_signal_connect(GTK_OBJECT(dialog), "destroy", \
			GTK_SIGNAL_FUNC(gtk_widget_destroy), &dialog);

	gtk_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(dialog)->ok_button), \
			"clicked", GTK_SIGNAL_FUNC(on_font_select_ok), \
			GTK_FONT_SELECTION_DIALOG(dialog));

	gtk_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(dialog)->cancel_button), \
			"clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), \
			GTK_OBJECT(dialog));
	gtk_widget_show(dialog);
}
void setButtonStyle(GtkWidget *button)
{
	gtk_widget_set_size_request(button, 80, 40);
}
int main(int argc, char *argv[])
{
	GtkWidget *window, *button, *hbox;
	
	gtk_init(&argc, &argv);
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
	gtk_container_set_border_width(GTK_CONTAINER(window), 10);
	gtk_widget_set_size_request(window, 270, 250);
	gtk_window_set_title(GTK_WINDOW(window), "TextView");	
	
	hbox = gtk_hbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(window), hbox);
	button = gtk_button_new_with_label("选择字体");
	gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_button_clicked), NULL);
	
	setButtonStyle(button);
	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
	gtk_widget_show_all(window);
	gtk_main();
	return 0;
}
